package com.crm.system.controller.orderManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.returnMoney.ReturnMoney;
import com.crm.model.vo.orderManager.OrderDetailDelVO;
import com.crm.system.service.orderManager.CustomerProductOrderDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: chaifuyou
 * @date 2021/3/29 17:12
 */
@RestController
@RequestMapping("/orderDetail")
@Slf4j
public class CustomerProductOrderDetailController {

    @Autowired
    private CustomerProductOrderDetailService customerProductOrderDetailService;

    /**
     * 删除订单产品
     * @return
     */
    @PostMapping("/delOrderDetail")
    public DataResponse delOrderDetail(@RequestBody OrderDetailDelVO delVo){
        try{
            //判断订单是否完成
            boolean b=customerProductOrderDetailService.ifOrderStatus(delVo.getOrderNumber());
            if (b){
                return new DhResponse(ResponseCodeEnum.ORDER_FINISH_BACK_MONEY.getResponseCode());
            }
            customerProductOrderDetailService.delOrderDetail(delVo);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
        }catch(Exception e){
            log.error("orderDetail delOrderDetail error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 根据订单标号查询退款记录
     * @return
     */
    @GetMapping("/getDelOrderProductLogList")
    public DataResponse getDelOrderProductLogList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                  @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                  @RequestParam String orderId){
        try{
            DhPageInfo<OrderDetailDelVO> page=customerProductOrderDetailService.getDelOrderProductLogList(orderId,pageIndex,pageSize);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),page);
        }catch(Exception e){
            log.error("orderDetail delOrderDetail error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }
}
